import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useStore = defineStore('counter', () => {
  const isShowStatistics = ref(false)
  function toggleShowStatistics() {
    isShowStatistics.value = !isShowStatistics.value
  }

  const isShowZongpingStatistics = ref(false)
  function toggleShowZongpingStatistics() {
    isShowZongpingStatistics.value = !isShowZongpingStatistics.value
  }

  const searchParams = ref({
    field_map_operates: [],
    page_no: 1,
    page_size: 30,
    wcsj_end_time: '',
    wcsj_start_time: '',
    wkt_cad_range: '',
    wkt_district: '',
    wkt_range: '',
    wkt_shp_range: [],
    table_name: '工程成果_验收',
  })

  function setSearchParams(params) {
    // searchParams.value = params
    // searchParams赋值为params的深拷贝
    searchParams.value = JSON.parse(JSON.stringify(params))
  }

  const areasByTime = ref(null)
  const areasAndCountByTime = ref(null)
  const dsByTime = ref(null)
  const dataByGn = ref(null)
  const dataByJc = ref(null)

  const mapByDataZP = ref(null)

  const mapByData = ref(null)
  const mapDataKey = ref(null)

  const areasByHeight = ref(null)
  const dsByHeight = ref(null)

  const layerByData = ref(null)
  const layerDataKey = ref(null)

  const feautres = ref([])
  const pushFeatures = (f) => {
    feautres.value.push(f)
  }

  const removeFeatures = () => {
    feautres.value.forEach((layer) => {
      window.map.removeLayer(layer)
    })
  }

  return {
    isShowStatistics,
    toggleShowStatistics,
    searchParams,
    setSearchParams,
    areasByTime,
    dsByTime,
    dataByGn,
    mapByData,
    mapDataKey,
    areasByHeight,
    dsByHeight,
    layerByData,
    layerDataKey,
    feautres,
    pushFeatures,
    removeFeatures,
    isShowZongpingStatistics,
    toggleShowZongpingStatistics,
    areasAndCountByTime,
    mapByDataZP,
    dataByJc,
  }
})
